<template>
  <div class="cart-box">
    <div class="mui-card" v-for="(val,i) in cartData" :key="val.id">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <mt-switch v-model="$store.getters.allSelected[val.id]" 
          @change="selectedAll(val.id,$store.getters.allSelected[val.id])">

          </mt-switch>
          <img :src="val.thumb_path" alt>
          <div>
            <h3>{{val.title}}</h3>
            <p>
              <span>￥{{val.sell_price}}</span>
              <btn :id="$store.getters.getCount[val.id]" :shopId="val.id"></btn>
              <a href="#" @click.prevent="remove(val.id,i)">删除</a>
            </p>
          </div>
        </div>
      </div>
    </div>
    <!-- 结算区域 -->
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <div>
            <p>总计(不包含运费)</p>
            <div class="div-box">
              <span>已勾选商品
                <i>{{$store.getters.countMoney.count}}</i>件
              </span>
              <span>总价
                <i>￥{{$store.getters.countMoney.money}}</i>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import btn from "./child/shopCar.vue";
export default {
  data() {
    return {
      cartData: ""
    };
  },
  created() {
    this.fn();
  },
  methods: {
    fn() {
      var idAll = [];
      this.$store.state.car.forEach(val => {
        idAll.push(val.id);
      });
      if (idAll.length <= 0) {
        return;
      }
      this.$http
        .get("api/goods/getshopcarlist/" + idAll.join(","))
        .then(res => {
          this.cartData = res.body.message;
        });
    },
    remove(id, i) {
      this.cartData.splice(i, 1);
      this.$store.commit("getRemove", id);
    },
    selectedAll(id,val) {
      this.$store.commit("selectedStatus", {id,selected:val});
    }
  },
  components: {
    btn
  }
};
</script>
<style scoped lang="less">

.cart-box {
  .mui-card-content-inner {
    display: flex;
    align-items: center;

    img {
      width: 60px;
      height: 60px;
      margin: 0 10px;
    }
    h3 {
      font-size: 15px;
    }
    p {
      display: flex;
    }
  }
  .div-box {
    margin: 10px 0;
    span {
      margin-right: 10px;
    }
    span:first-of-type i {
      color: red;
      margin:  0 2px;
    }
    span:last-of-type i {
      color: red;
    }
  }
}
</style>
